<?php

require_once dirname(__FILE__).'/../lib/reporteGeneratorConfiguration.class.php';
require_once dirname(__FILE__).'/../lib/reporteGeneratorHelper.class.php';

/**
 * reporte actions.
 *
 * @package    ingenyo-biblio
 * @subpackage reporte
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
 */
class reporteActions extends autoReporteActions
{
  public function executeIndex(sfWebRequest $request)
  {
    // sorting
    if ($request->getParameter('sort') && $this->isValidSortColumn($request->getParameter('sort')))
    {
      $this->setSort(array($request->getParameter('sort'), $request->getParameter('sort_type')));
    }

    // pager
    if ($request->getParameter('page'))
    {
      $this->setPage($request->getParameter('page'));
    }

    $this->pager = $this->getPager();
    $this->sort = $this->getSort();
    
    $this->generateReport();
  }
  
  public function executeFilter(sfWebRequest $request)
  {
    $this->setPage(1);

    if ($request->hasParameter('_reset'))
    {
      $this->setFilters($this->configuration->getFilterDefaults());

      $this->redirect('@reporte');
    }

    $this->filters = $this->configuration->getFilterForm($this->getFilters());

    $this->filters->bind($request->getParameter($this->filters->getName()));
    if ($this->filters->isValid())
    {
      $this->setFilters($this->filters->getValues());

      $this->redirect('@reporte');
    }

    $this->pager = $this->getPager();
    $this->sort = $this->getSort();

    $this->setTemplate('index');
  }

  public function generateReport(){
    $filters = $this->getFilters();
    $filters['idTipoPrestamo'] = null;
    $filtro = $this->configuration->getFilterForm($filters);
    $criteria = $filtro->buildCriteria($filters);
    
    $this->result_barra = BbPrestamoQuery::getBibliotecaReporteBarra($criteria);
    $this->result_area = BbPrestamoQuery::getBibliotecaReporteArea($criteria,$this->getFilters());
  }
}
